﻿//<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web; 
using System.Web.UI; 
using System.Web.Services;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Data.SqlClient;


namespace WebApplicationRating
{
    /// <summary>
    /// Summary description for Handler
    /// </summary>
    public class Handler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
                   
            
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings
                                  ["ConnectionString"].ConnectionString;

            //["imageConnectionString"].ConnectionString;
            // Create SQL Command 
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Select name,image_file from Image" +
                              " where imageid =@imageid";

            
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection = con;

            SqlParameter ImageID = new SqlParameter
                                ("@imageid", System.Data.SqlDbType.Int);
            ImageID.Value = context.Request.QueryString["imageid"];
            cmd.Parameters.Add(ImageID);
            con.Open();
            SqlDataReader dReader = cmd.ExecuteReader();
            dReader.Read();
            context.Response.BinaryWrite((byte[])dReader["image_file"]);  //use to be Image
            dReader.Close();
            con.Close();


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}